package edu.unika.aifb.graphindex.storage.lucene;

import org.apache.lucene.document.Field;

import edu.unika.aifb.graphindex.storage.DataField;
import edu.unika.aifb.graphindex.storage.IndexDescription;

public class LuceneUtil {
	public static int LUCENE_TERMINFO_INDEX_DIVISOR = 1;

	public static final String KEY_DELIM = Character.toString((char)31);
	
	public static String toIndexKey(String[] indexKeys) {
		StringBuilder sb = new StringBuilder();
		for (String s : indexKeys)
			sb.append(s).append(KEY_DELIM);
		return sb.toString();
	}

	protected static Field getIndexedField(IndexDescription index, String value) {
		Field f = new Field(index.getIndexFieldName(), value, Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS, Field.TermVector.NO);
		f.setOmitNorms(true);
		f.setOmitTermFreqAndPositions(true);
		return f;
	}
	
	protected static Field getStoredField(DataField df, String value) {
		Field f = new Field(df.toString(), value, Field.Store.YES, Field.Index.NO, Field.TermVector.NO);
		f.setOmitNorms(true);
		f.setOmitTermFreqAndPositions(true);
		return f;
	}

	protected static Field getStoredField(DataField df, byte[] value) {
		Field f = new Field(df.toString(), value, Field.Store.YES);
		f.setOmitNorms(true);
		f.setOmitTermFreqAndPositions(true);
		return f;
	}
}

